# -*- coding: utf-8 -*-
import logging
from pytdx.hq import TdxHq_API

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')


class Tdx_Client():

    def __init__(self, ip='111.229.247.189', port='7709'):
        self.ip = ip
        self.port = port
        self.api = TdxHq_API(auto_retry=True, raise_exception=False)
        self.api.connect(self.ip, int(self.port))

    def get_security_list(self, mkt_id, start):
        logging.info("获取股票列表")
        if self.api.connect(self.ip, int(self.port)):
            data = self.api.get_security_list(mkt_id, start)

            logging.info("list")
            logging.info(data)
            return data
        return None

    def get_security_quotes(self, all_stock, code=None):
        logging.info("获取股票行情")
        if self.api.connect(self.ip, int(self.port)):
            data = self.api.get_security_quotes(all_stock, code)
            return data or []
        return []


if __name__ == '__main__':
    tdx = Tdx_Client()

    dataList = tdx.get_security_list(1,0)
    print(dataList)

    data= tdx.get_security_quotes([(1, "600028")])
    print(data)



